package com.dqhl.business.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

import com.dqhl.business.R;
import com.dqhl.business.modle.GoodsManager;
import com.dqhl.business.util.Config;
import com.dqhl.business.util.ViewHolder;

import org.xutils.x;

import java.util.List;

/**
 * Created by guanluocang on 2016/11/6.
 */
public class GoodsManagerRecordAdapter extends BaseAdapter {
    private Context context;
    private List<GoodsManager> goodsManagersList;
    private LayoutInflater inflater;

    public GoodsManagerRecordAdapter(Context context, List<GoodsManager> goodsManagersList) {
        this.context = context;
        this.goodsManagersList = goodsManagersList;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return goodsManagersList.size();
    }

    @Override
    public Object getItem(int i) {
        return i;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        if (view == null) {
            view = inflater.inflate(R.layout.layout_good_managerrecord, viewGroup, false);
        }
        CheckBox ck_select = ViewHolder.get(view, R.id.ck_select);
        ImageView iv_goodsPic = ViewHolder.get(view, R.id.iv_goodsPic);
        TextView tv_goodsName = ViewHolder.get(view, R.id.tv_goodsName);
        TextView tv_goodsNum = ViewHolder.get(view, R.id.tv_goodsNum);
        TextView tv_goodsPrice = ViewHolder.get(view, R.id.tv_goodsPrice);

        GoodsManager goodsManager = goodsManagersList.get(i);

        tv_goodsName.setText(goodsManager.getName());
        tv_goodsNum.setText(goodsManager.getStock());
        tv_goodsPrice.setText(goodsManager.getPrice());
        if (!TextUtils.isEmpty(goodsManager.getPic_a())) {
            x.image().bind(iv_goodsPic, Config.img_url + goodsManager.getPic_a());
        }

        return view;
    }
}
